#!/bin/bash
echo ""
echo ""
echo "############################ 网络检查 ############################"
centosVersion=$(awk '{print $(NF-1)}' /etc/redhat-release)
if [[ $centosVersion < 7 ]];then
    /sbin/ifconfig -a | grep -v packets | grep -v collisions | grep -v inet6
else
#ip a
for i in $(ip link | grep BROADCAST | awk -F: '{print $2}');
    do 
        ip add show $i | grep -E "BROADCAST|global"| awk '{print $2}' | tr '\n' ' ' ;echo "" ;
    done
fi

GATEWAY=$(ip route | grep default | awk '{print $3}')
DNS=$(grep nameserver /etc/resolv.conf| grep -v "#" | awk '{print $2}' | tr '\n' ',' | sed 's/,$//')
echo ""
echo "网关：$GATEWAY "
echo " DNS：$DNS"
#报表信息
IP=$(ip -f inet addr | grep -v 127.0.0.1 | grep inet | awk '{print $NF,$2}' | tr '\n' ',' | sed 's/,$//')
MAC=$(ip link | grep -v "LOOPBACK\|loopback" | awk '{print $2}' | sed 'N;s/\n//' | tr '\n' ',' | sed 's/,$//')
report_IP="$IP" #IP地址
report_MAC=$MAC #MAC地址
report_Gateway="$GATEWAY" #默认网关
report_DNS="$DNS" #DNS


echo "############################ 网络检查结果 #############################"

echo "IP地址:$report_IP"
echo "MAC地址:$report_MAC"
echo "默认网关:$report_Gateway"
echo "DNS:$report_DNS"